//
//  NewsCell.m
//  QWwyNews
//
//  Created by Amisear on 15/10/7.
//  Copyright © 2015年 Amisear. All rights reserved.
//

#import "NewsCell.h"
#import <UIImageView+AFNetworking.h>

@interface NewsCell()

@property (strong, nonatomic) IBOutlet UIImageView *NewsImg;

@property (strong, nonatomic) IBOutlet UILabel *NewsTitle;

@property (strong, nonatomic) IBOutlet UILabel *NewsDigest;

@property (strong, nonatomic) IBOutlet UILabel *NewsReplyCount;

@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *thimg;




@end

@implementation NewsCell

- (void)setNews:(NewsModel *)news {
    
    _news = news;
    
    self.NewsTitle.text = news.title;
    self.NewsDigest.text = news.digest;
    self.NewsReplyCount.text = [NSString stringWithFormat:@"%d",news.replyCount];
    [self.NewsImg setImageWithURL:[NSURL URLWithString:news.imgsrc]];
    //判断有无多图
    if (news.imgextra.count == 2) {
        int index = 0;
        
        for (UIImageView *iv in self.thimg) {
            NSString *extraUrl = news.imgextra[index][@"imgsrc"];
            
//            self.thImgLable.text = news.title;
            
            NSURL *url = [NSURL URLWithString:extraUrl];
            
            [iv setImageWithURL:url];
            
            index++;
        }
        
    }
    
}

+ (NSString *)cellIdentifer:(NewsModel *)news {
    
    if (news.imgextra.count == 2) {
        return @"ThreeCell";
    }else if (news.isBigImage) {
        return @"BigImgCell";
    }
    return @"newsCell";
}


- (void)awakeFromNib {
    // Initialization code
    // 设置换行宽度
    self.NewsDigest.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - CGRectGetMaxX(self.NewsImg.frame) - 16;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
